{% macro submenuItem(name, url) %}
    {% if name|slice(0,1) != '_' %}
        <li>
            <a href='#{{ url|urlRewriteWithParameters|slice(1) }}'
               onclick='return piwikMenu.onItemClick(this);'>
                {{ name|translate }}
            </a>
        </li>
    {% endif %}
{% endmacro %}

{% macro groupedItem(name, group) %}
    <li>
        <div piwik-menudropdown show-search="true" menu-title="{{ name|translate|e('html_attr') }}">
            {% for item in group.getItems %}
                <a class="item"
                   href='#{{ item.url|urlRewriteWithParameters|slice(1) }}'
                   {% if item.tooltip %}title="{{ item.tooltip|e('html_attr') }}"{% endif %}
                   onclick='return piwikMenu.onItemClick(this);'>
                    {{ item.name|translate }}
                </a>
            {% endfor %}
        </div>
    </li>
{% endmacro %}

{% macro getId(urlParameters) -%}
    {% if urlParameters is iterable -%}
        {{ urlParameters|urlRewriteWithParameters }}
    {%- endif %}
{%- endmacro %}

{% macro getFirstUrl(urlParameters) -%}
    {% if urlParameters is iterable -%}
        {{ urlParameters|urlRewriteWithParameters|slice(1)  }}
    {%- endif %}
{%- endmacro %}

<div class="Menu--dashboard">

    <ul class="Menu-tabList">
        {% for level1,level2 in menu %}
            <li id="{% if level2._url is defined %}{{ _self.getId(level2._url) }}{% endif %}">
                <a {% if level2._url is defined %}href="#{{ _self.getFirstUrl(level2._url) }}"{% endif %}
                   onclick="return piwikMenu.onItemClick(this);">{{ level1|translate }}</a>
                <ul>

                {% for name,urlParameters in level2 %}
                    {% if urlParameters._url is defined and urlParameters._url is not iterable %}
                        {{ _self.groupedItem(name,urlParameters._url) }}
                    {% elseif name|slice(0,1) != '_' %}
                        {{ _self.submenuItem(name,urlParameters._url) }}
                    {% endif %}
                {% endfor %}

                </ul>
            </li>
        {% endfor %}
        <li id="Searchmenu">
            <span piwik-quick-access></span>
        </li>
    </ul>

</div>
<div class="nav_sep"></div>
